import {
	AppMenuActionType,
	IAppMenuAbility,
	IAppMenuControllerParams,
	IAppMenuModel,
	IAppMenuStore,
	ICtrlEvent,
	IParam,
} from '@/core';
import { QXEvent } from 'qx-util';
import {
	getCtrlClassNames,
	useCtrlAction,
	useCtrlBasic,
	useCtrlControllerParams,
	useCtrlProps,
} from '../use-ctrl';
import { PropType } from 'vue';

/**
 * 获取菜单输入参数
 *
 * @export
 * @return {*}
 */
export function useAppMenuProps() {
	return {
		...useCtrlProps(),
		viewStyle: {
			type: String,
			default: 'DEFAULT',
		},
		mode: {
			type: String,
			default: 'LEFT',
		},
		isDefaultPage: Boolean,
		isBlankMode: Boolean,
		defPSAppView: String,
		counterData: Object as PropType<IParam>,
	};
}

/**
 * 获取菜单基础
 *
 * @export
 * @param {IAppMenuModel} model 菜单模型
 * @param {IParam} props 输入参数
 * @return {*}
 */
export function useAppMenuBasic(model: IAppMenuModel, props: IParam) {
	const getClassNames = (props: IParam) => {
		const classNames = getCtrlClassNames(model, props);
		if (props.mode) {
			Object.assign(classNames, {
				[`app-control-menu--${props.mode.toLowerCase()}`]: true,
			});
		} else {
			Object.assign(classNames, { [`app-control-menu--left`]: true });
		}
		return classNames;
	};
	return {
		...useCtrlBasic(model, props),
		slotKeys: Object.keys(useSlots()),
		getClassNames,
	};
}

/**
 * 菜单行为
 *
 * @export
 */
export function useAppMenuAction(controller: any) {
	const handleMenuClick = (name: string) => {
		controller.handleMenuClick(name);
	};
	return {
		...useCtrlAction(controller),
		handleMenuClick,
	};
}

/**
 * 获取菜单部件控制器输入参数
 *
 * @export
 * @param {*} props
 * @param null evt
 */
export function useAppMenuControllerParams<
	S extends IAppMenuStore,
	M extends IAppMenuModel
>(
	model: M,
	props: any,
	evt: QXEvent<ICtrlEvent<AppMenuActionType, IAppMenuAbility>>,
	otherParams: IParam = {}
): IAppMenuControllerParams<AppMenuActionType, IAppMenuAbility> {
	return {
		...useCtrlControllerParams<S, M>(model, props, evt, otherParams),
		isDefaultPage: props.isDefaultPage,
		isBlankMode: props.isBlankMode,
		defPSAppView: props.defPSAppView,
		mode: props.mode,
	};
}
